// pages/my/my-returnBook/my-returnBook.js
var request = require('../../../utils/request.js');
var app = getApp();
Page({

  data: {
  
  },
  
  onLoad: function (options) {
  
  },
 
  onShow: function () {
    var that = this;
    that.getToken();
  },

  getToken: function () {
    var that = this;
    // 获取本地存储中的token
    wx.getStorage({
      key: 'token',
      success: function (res) {//有该数据
        console.log(res.data)
        that.setData({
          token: res.data
        })
        var tempToken  = res.data;
        request.getYouHuiList(
          { "session_id": tempToken },
          (res) => {
            console.log(res);
            //type=1新用户
            if (res.data.code == "1") {
              that.setData({
                isNew: true
              })
            } else {
              that.setData({
                isNew: false
              })
            }

          }
        )

      },
      fail: function (res) {
        console.log(res.data)
        //调用授权方法-设置token
        app.getUserInfo();
      }
    })
  },
  goScanCode:function(){
    wx.navigateBack({
      delta:4
    })
  },
  //查看附近书柜
  // goNearby: function () {
  //   wx.redirectTo({
  //     url: '../../index/index-nearby/index-nearby',
  //   })
  // },
  //书丢了
  goLooseBook:function(){
    var that  = this;
    if (that.data.isNew){
      wx.showModal({
        title: '书丢了',
        content: '您是月卡用户，将不会扣除您的借阅费用哦',
        confirmColor: "#ff0000",
        success: function (res) {
        }
      })
    }else{
      wx.showModal({
        title: '书丢了',
        content: '因图书丢失无法归还，会按照书本价格扣除相关费用。',
        confirmText: "去支付",
        confirmColor: "#ff0000",
        success: function (res) {
          if (res.confirm) {
            wx.redirectTo({
              url: '../my-wallet/my-wallet',
            })
          } else if (res.cancel) {
            wx.showToast({
              title: '支付后才能继续借书',
              image: "../../../images/xx.png"
            })
          }
        }
      })

    }
   
  }
})